package com.spike.service;

import com.spike.mapper.UserMapper;
import com.spike.model.User;
import com.spike.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

public class UserService {
//    通过账号密码登录
    public User findByUP(String username, String password) throws Exception {
        MyBatisUtils myBatisUtils = new MyBatisUtils();
        SqlSession sqlSession = myBatisUtils.getSqlSession();
        return sqlSession.getMapper(UserMapper.class).findByUP(username, password);
    }

    public int register(String username, String password) throws Exception {
        MyBatisUtils myBatisUtils = new MyBatisUtils();
        SqlSession sqlSession = myBatisUtils.getSqlSession();
        int i =  sqlSession.getMapper(UserMapper.class).register(username, password);
        sqlSession.commit();
        return i;
    }

}
